package com.waghost.bridalgown.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.waghost.bridalgown.annotaion.Logging;
import com.waghost.bridalgown.entity.Result;
import com.waghost.bridalgown.entity.UserInfo;
import com.waghost.bridalgown.service.UserInfoService;
import com.waghost.bridalgown.utils.UserUtils;
import lombok.AllArgsConstructor;
import lombok.extern.java.Log;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
// 用户
@RestController
@CrossOrigin
@AllArgsConstructor
public class UserInfoController {

    private UserInfoService userInfoService;
    private UserUtils userUtils;

    @GetMapping("/info")
    public Result getUserInfo(HttpServletRequest request) {
        return Result.success(userUtils.getUser(request));
    }

    @PostMapping("/login")
    @Logging(type = 5,uuid = 1)
    public Result login(@RequestBody UserInfo userInfo) {
        System.out.println(userInfo);
        return userInfoService.login(userInfo.getAccount(), userInfo.getPassword());
    }
    @PostMapping("/resetPwd")
    public Result resetPwd(@RequestBody UserInfo userInfo) {
        return userInfoService.resetPwd(userInfo);
    }
    @GetMapping("/user/list")
    public Result getUserList() {
        return userInfoService.listUsers();
    }

    // 获取首页推荐人员
    @GetMapping("/user/listTop")
    public Result getUserListTop() {
        return userInfoService.listUsersTop();
    }
    @GetMapping("/user/get/{id}")
    public Result getUserList(@PathVariable Integer id) {
        return userInfoService.getUser(id);
    }

    @PostMapping("/user/add")
    @Logging(type = 1,uuid = 1)
    public Result addUser(@RequestBody UserInfo userInfo) {
        return userInfoService.addUser(userInfo);
    }

    @PostMapping("/user/edit")
    @Logging(type = 3,uuid = 1)
    public Result editUser(@RequestBody UserInfo userInfo) {
        return userInfoService.updateUserInfo(userInfo);
    }

    @PostMapping("/user/del/{id}")
    @Logging(type = 2,uuid = 1)
    public Result delUser(@PathVariable("id")Integer id) {
        return userInfoService.deleteUser(id);
    }

}
